#!/usr/bin/env python
# encoding: utf-8

import smtplib
from email.mime.text import MIMEText
from email.header import Header

def SendEmail(fromAdd, toAdd, subject, attachfile, htmlText):
    strFrom = fromAdd
    strTo = toAdd
    msg = MIMEText(htmlText)
    msg['Content-Type'] = 'Text/HTML'
    msg['Subject'] = Header(subject, 'gb2312')
    msg['To'] = strTo
    msg['From'] = strFrom

    smtp = smtplib.SMTP('smtp.qq.com')
    smtp.login('user_name', '....');
    try:
        smtp.sendmail(strFrom, strTo, msg.as_string())
    finally:
        smtp.close();
if __name__ == "__main__":
    SendEmail()
